package com.caishi.lkx.order.config;


import com.caishi.lkx.exam.service.ICategoryService;
import com.caishi.lkx.exam.service.IColumnService;
import com.caishi.lkx.exam.service.IPackageSkuService;
import com.caishi.lkx.exam.service.IProductCodeService;
import com.caishi.lkx.order.CommonAssetsService;
import com.caishi.lkx.order.IAssetsModel;
import com.caishi.lkx.order.ienum.type.AssetsType;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.io.Serializable;

/**
 * @author by keray
 * date:2021/5/13 4:29 下午
 */
@Component
public class AssetsRouter {

    @Resource
    private IColumnService columnService;

    @Resource
    private IProductCodeService productCodeService;

    @Resource
    private ICategoryService categoryService;

    @Resource
    private IPackageSkuService packageSkuService;

    public <T extends IAssetsModel<T, ID>, ID extends Serializable> CommonAssetsService<T, ID> router(AssetsType assetsType) {
        if (assetsType == AssetsType.column) {
            return (CommonAssetsService<T, ID>) columnService;
        } else if (assetsType == AssetsType.category) {
            return (CommonAssetsService<T, ID>) categoryService;
        } else if (assetsType == AssetsType.skuCode) {
            return (CommonAssetsService<T, ID>) productCodeService;
        } else if (assetsType == AssetsType.product) {
            return (CommonAssetsService<T, ID>) packageSkuService;
        }
        return null;
    }

    public static AssetsRouter router;

    @PostConstruct
    public void init() {
        router = this;
    }
}
